<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="会员账号(字符串空：未插入)" prop="userAccountNo">
        <el-input v-model="dataForm.userAccountNo" placeholder="会员账号(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="微信ID(字符串空：未插入)" prop="outWxId">
        <el-input v-model="dataForm.outWxId" placeholder="微信ID(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="微信昵称(字符串空：未插入)" prop="outWxName">
        <el-input v-model="dataForm.outWxName" placeholder="微信昵称(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="推荐人parent_id邀请人用户ID(数字0：未插入)" prop="invitorId">
        <el-input v-model="dataForm.invitorId" placeholder="推荐人parent_id邀请人用户ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="邀请人的邀请码(字符串空：未插入)" prop="invitorCode">
        <el-input v-model="dataForm.invitorCode" placeholder="邀请人的邀请码(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="我的邀请码(字符串空：未插入)" prop="myCode">
        <el-input v-model="dataForm.myCode" placeholder="我的邀请码(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="邮寄地址即收货信息id(数字0：未插入)" prop="addressId">
        <el-input v-model="dataForm.addressId" placeholder="邮寄地址即收货信息id(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="昵称(字符串空：未插入)" prop="nickName">
        <el-input v-model="dataForm.nickName" placeholder="昵称(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="性别(数字0：未插入,1：男，2：女，3：保密)" prop="sex">
        <el-input v-model="dataForm.sex" placeholder="性别(数字0：未插入,1：男，2：女，3：保密)"></el-input>
      </el-form-item>
      <el-form-item label="年龄(数字0：未插入)" prop="age">
        <el-input v-model="dataForm.age" placeholder="年龄(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="生日(数字0：未插入)" prop="birthday">
        <el-input v-model="dataForm.birthday" placeholder="生日(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="登陆邮件(字符串空：未插入)" prop="emailLogin">
        <el-input v-model="dataForm.emailLogin" placeholder="登陆邮件(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否已发送邮件(数字0：未插入)" prop="sendEmailFlag">
        <el-input v-model="dataForm.sendEmailFlag" placeholder="是否已发送邮件(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否已认证邮箱(数字0：未插入)" prop="emailAvalidate">
        <el-input v-model="dataForm.emailAvalidate" placeholder="是否已认证邮箱(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="登陆手机(数字0：未插入)" prop="mobileLogin">
        <el-input v-model="dataForm.mobileLogin" placeholder="登陆手机(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否已发送短信(数字0：未插入)" prop="sendMessageFlag">
        <el-input v-model="dataForm.sendMessageFlag" placeholder="是否已发送短信(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否已认证手机(数字0：未插入)" prop="mobileAvalidate">
        <el-input v-model="dataForm.mobileAvalidate" placeholder="是否已认证手机(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="盐(字符串空：未插入)" prop="salt">
        <el-input v-model="dataForm.salt" placeholder="盐(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="登陆密码(字符串空：未插入)" prop="loginPwd">
        <el-input v-model="dataForm.loginPwd" placeholder="登陆密码(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否启用(数字0：未插入，1.未启用,2：启用，)" prop="enable">
        <el-input v-model="dataForm.enable" placeholder="是否启用(数字0：未插入，1.未启用,2：启用，)"></el-input>
      </el-form-item>
      <el-form-item label="操作员(字符串空：未插入)" prop="operator">
        <el-input v-model="dataForm.operator" placeholder="操作员(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建即上传时间(数字0：未插入)" prop="createUtc">
        <el-input v-model="dataForm.createUtc" placeholder="创建即上传时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="修改即更新时间(数字0：未插入)" prop="modifyUtc">
        <el-input v-model="dataForm.modifyUtc" placeholder="修改即更新时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否删除(数字0：未插入，1.未删除,2：删除，)" prop="isDeleted">
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除(数字0：未插入，1.未删除,2：删除，)"></el-input>
      </el-form-item>
      <el-form-item label="版本号(数字0：未插入)" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号(数字0：未插入)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userAccountNo: '',
          outWxId: '',
          outWxName: '',
          invitorId: '',
          invitorCode: '',
          myCode: '',
          addressId: '',
          nickName: '',
          sex: '',
          age: '',
          birthday: '',
          emailLogin: '',
          sendEmailFlag: '',
          emailAvalidate: '',
          mobileLogin: '',
          sendMessageFlag: '',
          mobileAvalidate: '',
          salt: '',
          loginPwd: '',
          enable: '',
          operator: '',
          createUtc: '',
          modifyUtc: '',
          isDeleted: '',
          version: ''
        },
        dataRule: {
          userAccountNo: [
            { required: true, message: '会员账号(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          outWxId: [
            { required: true, message: '微信ID(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          outWxName: [
            { required: true, message: '微信昵称(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          invitorId: [
            { required: true, message: '推荐人parent_id邀请人用户ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          invitorCode: [
            { required: true, message: '邀请人的邀请码(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          myCode: [
            { required: true, message: '我的邀请码(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          addressId: [
            { required: true, message: '邮寄地址即收货信息id(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          nickName: [
            { required: true, message: '昵称(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          sex: [
            { required: true, message: '性别(数字0：未插入,1：男，2：女，3：保密)不能为空', trigger: 'blur' }
          ],
          age: [
            { required: true, message: '年龄(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          birthday: [
            { required: true, message: '生日(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          emailLogin: [
            { required: true, message: '登陆邮件(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          sendEmailFlag: [
            { required: true, message: '是否已发送邮件(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          emailAvalidate: [
            { required: true, message: '是否已认证邮箱(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          mobileLogin: [
            { required: true, message: '登陆手机(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          sendMessageFlag: [
            { required: true, message: '是否已发送短信(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          mobileAvalidate: [
            { required: true, message: '是否已认证手机(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          salt: [
            { required: true, message: '盐(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          loginPwd: [
            { required: true, message: '登陆密码(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          enable: [
            { required: true, message: '是否启用(数字0：未插入，1.未启用,2：启用，)不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          createUtc: [
            { required: true, message: '创建即上传时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          modifyUtc: [
            { required: true, message: '修改即更新时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(数字0：未插入，1.未删除,2：删除，)不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号(数字0：未插入)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.upkuser.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userAccountNo = data.upkuser.userAccountNo
                this.dataForm.outWxId = data.upkuser.outWxId
                this.dataForm.outWxName = data.upkuser.outWxName
                this.dataForm.invitorId = data.upkuser.invitorId
                this.dataForm.invitorCode = data.upkuser.invitorCode
                this.dataForm.myCode = data.upkuser.myCode
                this.dataForm.addressId = data.upkuser.addressId
                this.dataForm.nickName = data.upkuser.nickName
                this.dataForm.sex = data.upkuser.sex
                this.dataForm.age = data.upkuser.age
                this.dataForm.birthday = data.upkuser.birthday
                this.dataForm.emailLogin = data.upkuser.emailLogin
                this.dataForm.sendEmailFlag = data.upkuser.sendEmailFlag
                this.dataForm.emailAvalidate = data.upkuser.emailAvalidate
                this.dataForm.mobileLogin = data.upkuser.mobileLogin
                this.dataForm.sendMessageFlag = data.upkuser.sendMessageFlag
                this.dataForm.mobileAvalidate = data.upkuser.mobileAvalidate
                this.dataForm.salt = data.upkuser.salt
                this.dataForm.loginPwd = data.upkuser.loginPwd
                this.dataForm.enable = data.upkuser.enable
                this.dataForm.operator = data.upkuser.operator
                this.dataForm.createUtc = data.upkuser.createUtc
                this.dataForm.modifyUtc = data.upkuser.modifyUtc
                this.dataForm.isDeleted = data.upkuser.isDeleted
                this.dataForm.version = data.upkuser.version
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'userAccountNo': this.dataForm.userAccountNo,
              'outWxId': this.dataForm.outWxId,
              'outWxName': this.dataForm.outWxName,
              'invitorId': this.dataForm.invitorId,
              'invitorCode': this.dataForm.invitorCode,
              'myCode': this.dataForm.myCode,
              'addressId': this.dataForm.addressId,
              'nickName': this.dataForm.nickName,
              'sex': this.dataForm.sex,
              'age': this.dataForm.age,
              'birthday': this.dataForm.birthday,
              'emailLogin': this.dataForm.emailLogin,
              'sendEmailFlag': this.dataForm.sendEmailFlag,
              'emailAvalidate': this.dataForm.emailAvalidate,
              'mobileLogin': this.dataForm.mobileLogin,
              'sendMessageFlag': this.dataForm.sendMessageFlag,
              'mobileAvalidate': this.dataForm.mobileAvalidate,
              'salt': this.dataForm.salt,
              'loginPwd': this.dataForm.loginPwd,
              'enable': this.dataForm.enable,
              'operator': this.dataForm.operator,
              'createUtc': this.dataForm.createUtc,
              'modifyUtc': this.dataForm.modifyUtc,
              'isDeleted': this.dataForm.isDeleted,
              'version': this.dataForm.version
            }
            var tick = !this.dataForm.id ? API.upkuser.add(params) : API.upkuser.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
